﻿@{
    ViewBag.Title = "UndulyFormBussiness";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
@using LeSoft.Application.Code;
<script>
    var _organizeid = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId"
    var keyValue = request('keyValue');
    var QCode = "";
    var MemberId;
    var State = 0;
    $(function () {
        InitialPage();
        InitControl();
        GetGrid1();
        GetGrid2();
    })
    //初始化数据
    function InitControl() {
        if (!!keyValue) {
            $.SetForm({
                url: "../../QualificationManage/Contract/GetUndulyContractInfo",
                param: { keyValue: keyValue },
                success: function (data) { 
                    $("#Info").SetWebControls(data.PStructInfo);
                    $("#Info").SetWebControls(data.PStruct);
                    $("#Info").SetWebControls(data.ContractDWelling);
                    MemberId = data.ContractDWelling.LiveInUserId;
                    $("#CompanyInfo").SetWebControls(data.CompanyInfo);
                    $("#Code").text(data.ContractDWelling.Code);

                    $("#EndDate").val(formatDate(data.ContractDWelling.EndDate, 'yyyy-MM-dd'))
                    $("#BeginDate").val(formatDate(data.ContractDWelling.BeginDate, 'yyyy-MM-dd'))

                    State = data.ContractDWelling.State;
                    if (data.ContractDWelling.State == 2) {
                        $(".BaseClass").attr("disabled", "disabled");
                        $("#lr-surrender").attr("hidden", "hidden");
                    } 
                    if (data.ContractDWelling.State == 3) {
                        $(".BaseClass").attr("disabled", "disabled");
                        $("#lr-enabled").attr("hidden", "hidden"); 
                    }
                    if (data.ContractDWelling.State == 5) {
                        $(".BaseClass").attr("disabled", "disabled");
                        $("#lr-business").attr("disabled", "disabled");
                    }
                    if (data.ContractDWelling.BeginDate != "" && data.ContractDWelling.EndDate != "") {
                        $("#RentYearDate").val(GetTimes(data.ContractDWelling.BeginDate, data.ContractDWelling.EndDate));
                    }
                    $("#MemberInfo").SetWebControls(data.MemberInfo);
                    $("#Description").val(data.ContractDWelling.Description)
                    $("#RoomCode").val(data.PStruct.Code);
                    $("#Area").val(data.Room.Area);
                    $("#HouseType").val(data.Room.HouseType);
                    $("#HouseTypeName").val(data.Room.HouseTypeName);
                    $("#QCode").html(data.Code);
                    GetGrid1(data.residentlist);
                    if (data.ContractDWelling.CommitDate == undefined) {
                        $("#CommitDate").val(formatDate(data.Room.EMoveInDate, 'yyyy-MM-dd'))
                    } else {
                        $("#CommitDate").val(formatDate(data.PStructInfo.CommitDate, 'yyyy-MM-dd'))
                    }
                    GetGrid2("[" + data.ContractDWelling.OperateMemo + "]");
                    GetAccessory(data.filelist);
                    $("#SignType").ComboBoxSetValue(data.ContractDWelling.SignType);


                }
            })
        }
    }
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        $('.profile-content').height($(window).height() - 20);
        $('.profile-nav').height($(window).height() - 20);
        //组织机构
        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: "250px",
            description: "===选择组织机构===",
            click: function (item) {
                _organizeid = item.id;
            }
        });
        $("#OrganizeId").ComboBoxSetValue(_organizeid);
        $("#SignType").ComboBox({
            data: [{ "key": "1", "value": "单位" }, { "key": "2", "value": "个人" }],
            id: "key",
            text: "value",
            description: "==签约主体==",
        });
        $("#Unit").ComboBox({
            data: [{ "key": "0", "value": "天" }, { "key": "1", "value": "周" }, { "key": "2", "value": "月" }, { "key": "3", "value": "季" }, { "key": "4", "value": "年" }],
            id: "key",
            text: "value",
            description: "==周期==",
        });
        $("#Unit").ComboBoxSetValue(2);

    };
    //侧面切换显示/隐藏
    function profileSwitch(id) {
        if (id == "BillContent") {
            $("#LogRecord").hide();
            $("#BillContent").show();
        }
        else {
            $("#BillContent").hide();
            $("#LogRecord").show();
        }
    };
    function GetGrid1(data) {
        $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            datatype: "json",
            height: 100,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "姓名", name: "Name", index: "Name", width: 200, align: "center", sortable: false },
                {
                    label: "性别", name: "Sex", index: "Sex", width: 200, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        switch (cellvalue) {
                            case 1:
                                return "男";
                            case 2:
                                return "女";
                            default: return cellvalue;
                        }
                    }
                },
                { label: "身份证号码", name: "IDCard", index: "IDCard", width: 300, align: "center", sortable: false },
                { label: "关系", name: "Relation", index: "Relation", width: 200, align: "center", sortable: false },
                {
                    label: "本市常住人口", name: "IsPermanent", index: "IsPermanent", width: 300, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        switch (cellvalue) {
                            case 0:
                                return "否";
                            case 1:
                                return "是";
                            default: return cellvalue;
                        }
                    }
                },
                { label: "婚姻状况", name: "MarryInfo", index: "MarryInfo", width: 300, align: "center", sortable: false },
                { label: "说明", name: "Description", index: "Description", width: 200, align: "center", sortable: false },

            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Date',
            sortorder: 'desc',
            rownumbers: true,
            gridview: true,
        })
        $gridTable[0].addJSONData(data);
    };
    function GetGrid2(data) {

        var selectedRowIndex = 0;
        $gridTable = $("#gridTable1");
        $gridTable.jqGrid({
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "操作时间", name: "Date", index: "Date", width: 300, align: "center", sortable: false },
                { label: "操作类型", name: "Type", index: "Type", width: 300, align: "center", sortable: false },
                { label: "操作人", name: "FormOperateName", index: "FormOperateName", width: 350, align: "center", sortable: false },
                { label: "操作描述", name: "Content", index: "Content", width: 600, align: "center", sortable: false },
            ],
            viewrecords: true,
            rownumbers: true,
            gridview: true,
            onSelectRow: function (status) {

            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        $gridTable[0].addJSONData(JSON.parse(data));

    };
    //获取附件信息
    function GetAccessory(data) {
        File = data;
        var html1 = "";
        var html2 = "";

        for (var i = 0; i < File.length; i++) {
            if (i <= 5) {
                switch (File[i].FileType) {

                    case 1: //图片
                        html1 += "<td><div class='CS_C'ondblclick='GetAccess(\"" + File[i].FileUrl + "\");'><div class=CS_T><img src='" + File[i].FileUrl + "'alt='加载失败' /></div><div class='CS_D'>" + File[i].FileName + "</div></div></td>"
                        break;
                    case 2: //语音
                        html1 += "<td><div class='CS_C' ondblclick='GetAccess(\"" + File[i].FileUrl + "\");'><div class=CS_T><i class='fa fa file-audio-o'></i></div><div class='CS_D'>" + File[i].FileName + "</div></div></td>"

                        break;
                    case 3: //视频
                        html1 += "<td><div class='CS_C' ondblclick='GetAccess(\"" + File[i].FileUrl + "\");'><div class=CS_T><i class='fa fa file-movie-o'></i></div><div class='CS_D'>" + File[i].FileName + "</div></div></td>"

                        break;
                    case 4: //zip压缩文件  fa fa-file-zip-o
                        html1 += "<td><div class='CS_C'ondblclick='GetAccess(\"" + File[i].FileUrl + "\");'><div class=CS_T><i  class='fa fa-file-zip-o'></i></div><div class='CS_D'>" + File[i].FileName + "</div></div></td>"

                        break;
                    case 5: //文档
                        html1 += "<td><div class='CS_C'ondblclick='GetAccess(\"" + File[i].FileUrl + "\");'><div class=CS_T><i class='fa fa file-word-o'></i></div><div class='CS_D'>" + File[i].FileName + "</div></div></td>"
                        break;
                    default: break;

                }
            } else {
                switch (File[i].FileType) {

                    case 1: //图片
                        html2 += "<td><div class='CS_C'ondblclick='GetAccess(\"" + File[i].FileUrl + "\");'><div class=CS_T><img src='" + File[i].FileUrl + "'alt='加载失败' /></div><div class='CS_D'>" + File[i].FileName + "</div></div></td>"
                        break;
                    case 2: //语音
                        html2 += "<td><div class='CS_C' ondblclick='GetAccess(\"" + File[i].FileUrl + "\");'><div class=CS_T><i class='fa fa file-audio-o'></i></div><div class='CS_D'>" + File[i].FileName + "</div></div></td>"

                        break;
                    case 3: //视频
                        html2 += "<td><div class='CS_C' ondblclick='GetAccess(\"" + File[i].FileUrl + "\");'><div class=CS_T><i class='fa fa file-movie-o'></i></div><div class='CS_D'>" + File[i].FileName + "</div></div></td>"

                        break;
                    case 4: //zip压缩文件  fa fa-file-zip-o
                        html2 += "<td><div class='CS_C'ondblclick='GetAccess(\"" + File[i].FileUrl + "\");'><div class=CS_T><i  class='fa fa-file-zip-o'></i></div><div class='CS_D'>" + File[i].FileName + "</div></div></td>"

                        break;
                    case 5: //文档
                        html2 += "<td><div class='CS_C'ondblclick='GetAccess(\"" + File[i].FileUrl + "\");'><div class=CS_T><i class='fa fa file-word-o'></i></div><div class='CS_D'>" + File[i].FileName + "</div></div></td>"
                        break;
                    default: break;

                }
            }

        }
        $("#CS_IO").html(html1);
        $("#CS_IO1").html(html2);
    };
    //查看及下载附件
    function GetAccess(Url) {
        a = window.open(Url, "_blank", "width=500, height=500,status=0");

    };
    //合同操作
    function btn_Save(s) {
        dialogConfirm('该操作执行后将无法逆转,是否继续！', function (r) {
            if (r) {
                $.SaveForm({
                    url: "../../QualificationManage/Contract/SaveUndulyBussiness", 
                    param: { keyValue: keyValue, Type: s },
                    loading: "正在保存数据...",
                    success: function () {
                        location.reload();
                    }
                })
            }
        });

    }

    //获取数据
    function GetTimes(sdate, edate) {
        var Sdate = new Date(Date.parse(sdate.replace(/-/g, "/"))).getTime();
        var Edate = new Date(Date.parse(edate.replace(/-/g, "/"))).getTime();
        var a = Math.floor((Edate - Sdate) / 86400000);
        var y = Math.floor(a / 365);
        var m = Math.floor((a - y * 365) / 30);
        var d = (a - y * 365 - m * 30);
        if (a > 365) {
            dialogMsg("租赁时限不能大于1年。", 0);
            return false;
        }
        var RentYearDate = "";
        if (m >= 12) {
            y++;
            m = m - 12;
        }
        if (y >= 1) {
            RentYearDate += y + "年";
        }
        if (m >= 1) {
            RentYearDate += m + "个月"
        }

        if (d >= 1) {
            RentYearDate += d + "天";
        }
        $("#RentYear").val(a);
        return RentYearDate;
    };
    //计算时间戳
    function GetDateTimes() {
        var BeginDate = $("#BeginDate").val();
        var EndDate = $("#EndDate").val();
        if (BeginDate != "" && EndDate != "") {
            $("#RentYearDate").val(GetTimes(BeginDate, EndDate) == false ? "" : GetTimes(BeginDate, EndDate));
        }
    };


</script>
<style>
    .CS_C {
        margin: 10px;
        width: 148px;
        height: 110px;
        border: solid 1px #F0F0F0;
        margin-right: 10px;
    }

        .CS_C:hover {
            border: solid 1px #AFD4FA;
            background-color: #F5FAFF;
        }

    .CS_T {
        width: 148px;
        height: 70px;
        line-height: 70px;
        text-align: center;
    }

        .CS_T img {
            width: 50px;
        }

    .CS_D {
        width: 148px;
        height: 40px;
        text-align: center;
    }

    i {
        transform: scale(2.5);
        -webkit-transform: scale(2.5);
        -moz-transform: scale(2.5);
        -o-transform: scale(2.5);
        -ms-transform: scale(2.5);
    }

    .formTitle {
        text-align: right;
    }
</style>
<style>
    .curved_box {
        display: inline-block;
        *display: inline;
        width: 70%;
        height: 1800px;
        margin: 20px;
        margin-left: 15%;
        padding: 50px;
        padding-top: 20px;
        background-color: #fff;
        border: 1px solid #eee;
        -webkit-box-shadow: 0 1px 40px rgba(0, 0, 0, 0.27), 0 0 60px rgba(0, 0, 0, 0.06) inset;
        -moz-box-shadow: 0 1px 40px rgba(0, 0, 0, 0.27), 0 0 40px rgba(0, 0, 0, 0.06) inset;
        box-shadow: 0 1px 40px rgba(0, 0, 0, 0.27), 0 0 40px rgba(0, 0, 0, 0.06) inset;
        position: relative;
        *zoom: 1;
    }
</style>
<div style="position:absolute;top:0; right:80px;z-index:1000;background:rgba(0, 0, 0, 0.1);padding:10px;border-radius:0px 0px 5px 5px;">
    <div class="btn-group">
        <a class="btn btn-default" id="lr-business" data-toggle="dropdown">业务<span class="caret"></span></a>
        <ul class="dropdown-menu">
            <li id="lr-enabled"><a onclick="btn_Save(3)">启用</a></li>
            <li id="lr-surrender"><a onclick="btn_Save(5)">退租</a></li>
        </ul>
    </div>
</div>

<div class="ui-layout" id="layout" style="height: 100%;  width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="profile-nav">
                <ul style="padding-top: 20px;">
                    <li class="active" onclick="profileSwitch('BillContent')">基础信息</li>
                    <li onclick="profileSwitch('LogRecord')">业务日志</li>
                </ul>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">

            <div class="profile-content" style="background: #fff; ">

                <div id="BillContent">
                    <div class="curved_box">

                        <div class="title" style="font-size:18px; font-weight:normal;">
                            基本信息
                        </div>
                        <table class="form" id="Info" style="margin-top:20px;">
                            <tr>
                                <td class="formTitle cs-1">所属机构</td>
                                <td class="formValue"><div id="OrganizeId" type="selectTree" disabled readonly class="ui-select "></div></td>
                                <td class="formTitle">合同编号：</td>
                                <td class="formValue "><input class="form-control" readonly disabled id="Code" type="text" /></td>
                                <td class="formTitle cs-1">签约时间</td>
                                <td class="formValue"><input id="SignDate" type="text" class="form-control input-wdatepicker BaseClass " placeholder="请输入签约时间" value="@LeSoft.Util.Time.GetToday("yyyy-MM-dd HH-mm-ss ")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd  HH:mm:ss  ' })" /></td>
                            </tr>
                            <tr>
                                <td class="formTitle cs-1">租赁房屋</td>
                                <td class="formValue" colspan="3"><input class="form-control" disabled readonly id="AllName" type="text" /></td>
                                <td class="formTitle cs-1">房屋编号</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="RoomCode" type="text" /></td>

                            </tr>
                            <tr>
                                <td class="formTitle cs-1">建筑面积</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="Area" type="text" /></td>
                                <td class="formTitle">户型</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="HouseTypeName" type="text" /></td>
                                <td class="formTitle">朝向</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="HouseType" type="text" /></td>
                            </tr>
                            <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="4"></td> </tr>
                            <tr>
                                <td colspan="6">
                                    <div class="title" style="font-size: 18px; font-weight: normal;">
                                        租赁信息
                                    </div>
                                </td>
                            </tr>
                            <tr style="height: 20px;"><td colspan="6"></td> </tr>
                            <tr style="margin-top:20px;">
                                <td class="formTitle">租赁开始日期<font face="宋体">*</font></td>
                                <td class="formValue"><input id="BeginDate" type="text" disabled readonly class="form-control input-wdatepicker BaseClass " isvalid="yes" checkexpession="NotNull" placeholder="请输入租赁开始日期" value="@LeSoft.Util.Time.GetToday("yyyy-MM-dd ")" onblur="GetDateTimes();" onfocus="WdatePicker({maxDate: '#F{$dp.$D(\'EndDate\')}'});" /></td>
                                <td class="formTitle">租赁结束日期<font face="宋体">*</font></td>
                                <td class="formValue"><input id="EndDate" type="text" disabled readonly class="form-control input-wdatepicker BaseClass" isvalid="yes" checkexpession="NotNull" placeholder="请输入租赁结束日期" value="@LeSoft.Util.Time.GetToday("yyyy-MM-dd ")" onblur="GetDateTimes();" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'BeginDate\')}'});" /></td>
                                <td class="formTitle">租赁年限<font face="宋体">*</font></td>
                                <td class="formValue">
                                    <input id="RentYear" class="form-control" type="hidden" />
                                    <input id="RentYearDate" class="form-control BaseClass" disabled type="text" isvalid="yes" checkexpession="NotNull" />
                                </td>
                            </tr>
                            <tr>
                                <td class="formTitle">交房日期<font face="宋体">*</font></td>
                                <td class="formValue"><input id="CommitDate" type="text" class="form-control input-wdatepicker BaseClass " isvalid="yes" checkexpession="NotNull" placeholder="请输入交房日期" value="@LeSoft.Util.Time.GetToday("yyyy-MM-dd ")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd ' })" /></td>
                                <td class="formTitle">每月租金<font face="宋体">*</font></td>
                                <td class="formValue"><input class="form-control BaseClass" id="MonthlyRent" isvalid="yes" checkexpession="NotNull" type="number" /></td>
                                <td class="formTitle">应付押金<font face="宋体">*</font></td>
                                <td class="formValue"><input class="form-control BaseClass" id="Deposit" isvalid="yes" checkexpession="NotNull" type="number" /></td>

                            </tr>
                            <tr>
                                <td class="formTitle">付费周期<font face="宋体">*</font></td>
                                <td class="formValue">
                                    <table class="form">
                                        <tr>
                                            <td class="formValue"><input id="UnitNum" isvalid="yes" class="form-control BaseClass" checkexpession="NotNull" type="number" value="1" min="1" style="width:100px;" /></td>
                                            <td class="formValue"><div id="Unit" isvalid="yes" checkexpession="NotNull" type="selectTree" class="ui-select BaseClass" style="width: 100px;   border:#ccc 1px solid;"></div></td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="6"></td> </tr>
                            <tr>
                                <td colspan="6">
                                    <div class="title" style="font-size: 18px; font-weight: normal;">
                                        承租人信息
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <table class="form" id="MemberInfo" style="margin-top:20px;">
                            <tr>
                                <td class="formTitle">入住人姓名</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="Name" type="text" /></td>
                                <td class="formTitle">入住人编号</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="Code" type="text" /></td>
                                <td class="formTitle">联系电话</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="TelPhoneNum" type="text" /></td>
                            </tr>
                            <tr>
                                <td class="formTitle">身份证号码</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="CertificateNO" type="text" /></td>
                                <td class="formTitle">委托代理人</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="LinkMan" type="text" /></td>
                                <td class="formTitle">代理人电话</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="LinkPhoneNum" type="text" /></td>
                            </tr>
                        </table>
                        <table class="form" id="CompanyInfo">
                            <tr>
                                <td class="formTitle">单位编号</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="Code" type="text" /></td>
                                <td class="formTitle">营业执照编号</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="Licene" type="text" /></td>
                                <td class="formTitle">法人代表</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="Legal" type="text" /></td>
                            </tr>
                            <tr>
                                <td class="formTitle">入住人单位</td>
                                <td class="formValue" colspan="5"><input class="form-control" disabled readonly id="Name" type="text" /></td>
                            </tr>

                            <tr>
                                <td class="formTitle">单位地址</td>
                                <td class="formValue" colspan="5"><input class="form-control" disabled readonly id="Address" type="text" /></td>
                            </tr>
                            <tr>
                                <td class="formTitle">联系电话</td>
                                <td class="formValue"><input class="form-control" disabled readonly id="TelPhoneNum" type="text" /></td>
                                <td class="formTitle">签约主体</td>
                                <td class="formValue"><div id="SignType" disabled readonly type="selectTree" class="ui-select"></div></td>

                            </tr>
                            <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="6"></td> </tr>
                            <tr><td colspan="6"><div class="panel-Title" style="border: 0px; font-size: 18px; font-weight: normal;">同住人</div></td></tr>
                            <tr style=" height: 10px;"><td colspan="6"></td> </tr>
                            <tr>
                                <td colspan="6">
                                    <div class="center-Panel">
                                        <div class="gridPanel">
                                            <table id="gridTable"></table>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="6"></td> </tr>
                            <tr style=" height: 20px;"><td colspan="6"></td> </tr>
                            <tr><td colspan="6"><div class="panel-Title" style="border: 0px; font-size: 18px; font-weight: normal;">附加说明</div></td></tr>
                            <tr>
                                <td class="formValue" colspan="6"><textarea id="Description" class="form-control BaseClass" readonly style="height: 80px;"></textarea></td>
                            </tr>
                            <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="6"></td> </tr>
                            <tr><td colspan="6"><div class="panel-Title" style="border: 0px; font-size: 18px; font-weight: normal;">附件</div></td></tr>

                        </table>
                        <table class="from">
                            <tr id="CS_IO"></tr>
                            <tr id="CS_IO1"></tr>
                            <tr style=" height: 20px;"><td colspan="4"></td> </tr>
                        </table>
                    </div>

                </div>
                <div id="LogRecord" style="display: none;">
                    <div class="title">
                        操作日志
                    </div>
                    <div class="gridPanel">
                        <table id="gridTable1"></table>
                    </div>

                </div>

            </div>
        </div>
    </div>
</div>
